﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

/// <summary>
/// Utility class for Web Parts
/// author: Jeff
/// date: 04/26/2008
/// </summary>
public class WebPartUtil
{
    /// <summary>
    /// NOT USED
    /// </summary>
	public WebPartUtil()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    /// <summary>
    /// Set Web Parts of a WebPartZone to display mode 
    /// </summary>
    /// <param name="wpz">WebPartZone wpz</param>
    public static void SetWebPartZone(WebPartZone wpz, Boolean editable)
    {
        WebPartCollection wpc = wpz.WebParts;
        wpz.DeleteVerb.Visible = editable;
        wpz.DeleteVerb.Enabled= editable;
        wpz.CloseVerb.Visible = editable;
        wpz.CloseVerb.Enabled = editable;
        wpz.MinimizeVerb.Visible = editable;
        wpz.MinimizeVerb.Enabled = editable;
    }
}

namespace Citiport
{
    /// <summary>
    /// Classs for making my/Default.aspx works!
    /// </summary>
    public class SqlPersonalizationProvider : System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider
    {
        private String GetPath
        {
            get
            {
                HttpContext context = HttpContext.Current;

                if (context == null)
                    throw new HttpException("Context can not be Null");

                HttpRequest request = context.Request;
                if (request == null)
                    throw new HttpException("The current Context's Request property can not be Null");

                return this.CreateUrl(request);
            }
        }

        private String CreateUrl(HttpRequest request)
        {
            String url = request.Url.PathAndQuery;
            return url;
        }

        protected override void SavePersonalizationBlob(WebPartManager webPartManager, string path, string userName, byte[] dataBlob)
        {
            
            base.SavePersonalizationBlob(webPartManager, this.GetPath, userName, dataBlob);
        }

        protected override void LoadPersonalizationBlobs(WebPartManager webPartManager, string path, string userName, ref byte[] sharedDataBlob, ref byte[] userDataBlob)
        {
            base.LoadPersonalizationBlobs(webPartManager, this.GetPath, userName, ref sharedDataBlob, ref userDataBlob);
        }

        protected override void ResetPersonalizationBlob(WebPartManager webPartManager, string path, string userName)
        {
            base.ResetPersonalizationBlob(webPartManager, this.GetPath, userName);
        }
    }
}